var express = require('express');
const {
    saveQuestionnaire, selectQuestionnaire, deleteQuestionnaire, modifyQuestionnaire, publishQuestionnaire,
    selectPublishedList, deletePublished, modifyDeadLine, submitAnswer, submitAnalysis, getAnalysisResult,
    deleteAnalysisResult
} = require("../services/questionnaire");
const {fetchSubmitted, deleteAnsweredQuestionnaire, countPercentage} = require("../services/questionnaire/answer");
var router = express.Router();

router.get('/questionnaireList', async (req, res) => {
    await selectQuestionnaire(res)
})
router.post('/questionnaire', async (req, res) => {
    await saveQuestionnaire(req.body, res)
})
router.delete('/questionnaire', async (req, res) => {
    await deleteQuestionnaire(req.query, res)
})
router.put('/questionnaire', async (req, res) => {
    await modifyQuestionnaire(req.body, res)
})
router.post('/publish', async (req, res) => {
    await publishQuestionnaire(req.body, res)
})
router.get('/publishedList', async (req, res) => {
    await selectPublishedList(res)
})
router.delete('/deletePublished', async (req, res) => {
    // console.log(req.query,'删除id')
    await deletePublished(req.query, res)
})
router.put('/deadline', async (req, res) => {
    await modifyDeadLine(req.body, res)

})
router.post('/question/submit', async (req, res) => {
    await submitAnswer(req.body, res)
})
router.get('/question/submitted', async (req, res) => {
    await fetchSubmitted(req.query, res)
})
router.delete('/submitted', async (req, res) => {
    await deleteAnsweredQuestionnaire(req.query, res)
})
router.get('/count', async (req, res) => {
    await countPercentage(req.query, res)
})
router.post('/analysis', async (req, res) => {
    await submitAnalysis(req.body, res)
})
router.get('/analysis', async (req, res) => {
    await getAnalysisResult(res)
})
router.delete('/analysis', async (req, res) => {
    await deleteAnalysisResult(req.query, res)
})
module.exports = router;
